package main

import (
	"./html"
	"fmt"
	"net"
	"log"
)

var content = `HTTP/1.1 200 OK
 Date: Sat, 29 Jul 2017 06:18:23 GMT
 Content-Type: text/html
 Connection: Keep-Alive
 Server: BWS/1.1
 X-UA-Compatible: IE=Edge,chrome=1
 BDPAGETYPE: 3
 Set-Cookie: BDSVRTM=0; path=/


`

func main()  {
	url := "http://wwww.baidu.com"
	fmt.Printf("--------------------------------------visit:%v-------------------------------------- \n", url)
	addr := "0.0.0.0:8080"
	listener, err := net.Listen("tcp", addr);
	if err != nil{
		log.Fatal(err)
	}
	defer listener.Close()
	for {
		conn, err := listener.Accept();
		if err != nil{
			log.Fatal(err)
		}
		go handler(conn, content+html.GetHtml(url))
	}
	fmt.Printf("--------------------------------------visit end:%v-------------------------------------- \n", url)
}

func handler(conn net.Conn, str string)  {
	fmt.Println(str)
	conn.Write([]byte(str))
	conn.Close()
}